package com.boot41p.controller;

import com.boot41p.entity.Product;
import com.boot41p.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author wxd
 * @version 1.0
 */
@RestController
public class ProductController {
    @Autowired
    ProductMapper mapper;

    @RequestMapping("/insertProduct")
    public void insertProduct(@RequestBody Product product) {
        mapper.insert(product);
    }

    @RequestMapping("/selectProduct")
    public List<Product> select() {
        return mapper.select();
    }

    @RequestMapping("/deleteProduct")
    public void delete(int id) {
        mapper.deleteById(id);
    }

    @RequestMapping("/selectById")
    public Product selectById(int id) {
        return mapper.selectById(id);
    }

    @RequestMapping("/updateProductById")
    public void updateProduct(@RequestBody Product product) {
        mapper.updateById(product);
    }
}
